using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;

namespace Tyng.Web.UI.YUI
{
    public class Alignment
    {
        Corner _parent;
        Corner _child;

        public Alignment(Corner child, Corner parent)
        {
            _parent = parent;
            _child = child;
        }

        [JsonIgnore]
        public Corner ParentCorner
        {
            get
            {
                return _parent;
            }
            set
            {
                _parent = value;
            }
        }

        [JsonIgnore]
        public Corner ChildCorner
        {
            get
            {
                return _child;
            }
            set
            {
                _child = value;
            }
        }

        public static string GetCornerString(Corner c)
        {
            switch(c)
            {
                case Corner.TopLeft:
                    return "tl";
                case Corner.TopRight:
                    return "tr";
                case Corner.BottomRight:
                    return "br";
                case Corner.BottomLeft:
                    return "bl";
                default:
                    throw new NotSupportedException();
            }
        }
    }

    public class AlignmentJsonConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return typeof(Alignment).IsAssignableFrom(objectType);
        }

        public override void WriteJson(JsonWriter writer, object value)
        {
            Alignment typedValue = (Alignment)value;

            writer.WriteStartArray();
            writer.WriteValue(Alignment.GetCornerString(typedValue.ParentCorner));
            writer.WriteValue(Alignment.GetCornerString(typedValue.ChildCorner));
            writer.WriteEndArray();
        }

        public override object ReadJson(JsonReader reader, Type objectType)
        {
            throw new NotImplementedException();
        }
    }
}
